/**
 * 角色路由模块
 */

const express = require('express');
const roleController = require('../controllers/roleController');
const { authenticateToken } = require('../middlewares/authMiddleware');
const { checkPermission , checkPermissionLevel} = require('../middlewares/permissionMiddleware');

const router = express.Router();

// 所有用户路由都需要认证Token
router.use(authenticateToken);

// 数据域类接口（通用接口，需要控制范围）

// 获取当前用户的权限菜单是否变化更新（判断是否需要更新前端menu）
router.get('/checkupdate', checkPermission('role:check:update'), roleController.checkRoleUpdate);

// 管理类接口（需要管理员权限）

// 获取角色列表
router.get('/', checkPermission('role:list'), checkPermissionLevel(40), roleController.getAllRoles);

// 获取用户已绑定角色列表
router.post('/bindlist', checkPermission('role:list:bind'), checkPermissionLevel(40), roleController.getBindRoles);

// 创建角色
router.post('/', checkPermission('role:create'), checkPermissionLevel(40), roleController.createRole);

// 删除多个用户
router.delete('/batch', checkPermission('role:batch:delete'), checkPermissionLevel(40), roleController.removeBatchRoles);

// 编辑角色
router.put('/update', checkPermission('role:update'), checkPermissionLevel(40), roleController.updateRole);

// 绑定角色菜单
router.post('/bindmenus', checkPermission('role:bind:menus'), checkPermissionLevel(40), roleController.bindMenus);

// 角色批量绑定用户
router.post('/bindusers', checkPermission('role:bind:users'), checkPermissionLevel(40), roleController.batchBindUsers);

// 获取角色已绑定菜单
router.get('/bindmenus/:id', checkPermission('role:view:menus'), checkPermissionLevel(40), roleController.getBindMenus);

// 获取角色已绑定用户
router.get('/bindusers/:id', checkPermission('role:view:users'), checkPermissionLevel(40), roleController.getBindUsers);

// 获取角色已绑定权限
router.get('/bindpermissions/:id', checkPermission('role:view:permissions'), checkPermissionLevel(40), roleController.getBindPermissions);

// 删除单个角色
router.delete('/:id', checkPermission('role:delete'), checkPermissionLevel(40), roleController.removeRole);

// 获取角色详情
router.get('/:id', checkPermission('role:view'), checkPermissionLevel(40), roleController.getRoleById);

// 获取角色数据权限
// router.get('/:roleId/data-permissions', checkPermission('role:view:data'), roleController.getRoleDataPermissions);

// 分配角色数据权限
// router.put('/:roleId/data-permissions', checkPermission('role:update:data'), roleController.assignRoleDataPermissions);

module.exports = router;